class Solution413 {
    public int numberOfArithmeticSlices(int[] nums) {
        if(nums.length <= 2) return 0 ;
        int n = nums.length ;
        // 以 i 结尾 有多少个 等差子数组 
        int[] dp = new int[n] ;
        dp[0] =   dp[1] = 0 ; 
        int prev = nums[1] - nums[0] ;  // 记录当前公差
        int count = 0 ;
        for(int i=2 ; i < n ; i ++){
             int cur = nums[i] - nums[i-1] ; 
             if(cur == prev){
                // 
                dp[i] = dp[i-1] + 1 ; 
             }else{
                dp[i] = 0 ; 
                prev = cur ; 
             }
            count += dp[i] ; 
        }
         return count ; 
    }
}